package com.J1ay.carsys.dao;

import com.J1ay.carsys.pojo.BowCar;
import com.J1ay.carsys.pojo.Bower;
import com.J1ay.carsys.pojo.Car;
import com.J1ay.carsys.utils.IDutils;
import com.J1ay.carsys.utils.Md5Util;
import com.J1ay.carsys.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.Date;
import java.util.List;

/**
 * @Author J1ay
 * @Date 2021/6/2 18:38
 * @Description
 */

public class DbTestDao {
    @Test
    public void test(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BowerMapper bowerMapper = sqlSession.getMapper(BowerMapper.class);

        sqlSession.close();
    }

    @Test
    public void getBowerByPhone(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BowerMapper bowerMapper = sqlSession.getMapper(BowerMapper.class);
        System.out.println(bowerMapper.getBowerByPhone("17816942800"));
        sqlSession.close();
    }

    @Test
    public void addBower(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BowerMapper bowerMapper = sqlSession.getMapper(BowerMapper.class);
        Bower bower = new Bower();
        bower.setUId(""+(new Date()).getTime());
        bower.setBname("勒酱");
        bower.setEcard("331081200108221206");
        bower.setEmpId(1);
        bower.setPhone("17816942800");
        bower.setCreateTime(new Date());
        if(bower.getEcard().length() == 18 || bower.getEcard().length() == 15){
            bowerMapper.addBower(bower);
        }
       else{
           System.out.println("身份证格式不对");
        }

        sqlSession.close();
    }

    @Test
    public void update(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BowerMapper bowerMapper = sqlSession.getMapper(BowerMapper.class);
        Bower bower = new Bower();
        System.out.println((new Date()).getTime());
        bower.setUId("202101");
        bower.setBname("李四");
        bower.setEcard("331081200104118912");
        bowerMapper.updateBower(bower);
        sqlSession.close();
    }

    @Test
    public void deleteBower(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BowerMapper bowerMapper = sqlSession.getMapper(BowerMapper.class);
        int res = bowerMapper.deleteBower("1622643175232","17816942800");
        if (res > 0) {

        }
        else{
            System.out.println("null");
        }
        sqlSession.close();
    }

    @Test
    public void addCar(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        CarMapper carMapper = sqlSession.getMapper(CarMapper.class);
        Car car = new Car();
        carMapper.addCar(car);
        sqlSession.close();
    }

    @Test
    public void updateCar(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        CarMapper carMapper = sqlSession.getMapper(CarMapper.class);
        Car car = new Car();
        carMapper.updateCar(car);
        sqlSession.close();
    }

    @Test
    public void addRecord(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BowCarMapper bowCarMapper = sqlSession.getMapper(BowCarMapper.class);
        BowCar bowCar = new BowCar();
        bowCar.setSn(IDutils.getId());
        bowCar.setUId("202101");
        bowCar.setCarId(1);
        bowCar.setEmpId(1);
        bowCar.setBowDay(5);
        bowCar.setBowPrice(100);
        bowCar.setBowCreate(new Date());
        bowCarMapper.addRecord(bowCar);
        sqlSession.close();
    }
    @Test
    public void updateRecord(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BowCarMapper bowCarMapper = sqlSession.getMapper(BowCarMapper.class);
        BowCar bowCar = new BowCar();
        bowCar.setSn(IDutils.getId());
        bowCar.setBowId(1);
//        bowCar.setBow_result("fail");
        bowCar.setBowStatus("undone");
        bowCarMapper.updateRecord(bowCar);
        sqlSession.close();
    }
    @Test
    public void getUnBowCar() {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        CarMapper carMapper = sqlSession.getMapper(CarMapper.class);
//        carMapper.getUnBowCar();
        Car[] carList = carMapper.getUnBowCar();
        System.out.println(carList);
        for (Car car : carList){
            System.out.println(car);
        }
        sqlSession.close();
    }
}
